/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.np2tec.soa.servicos;

import br.np2tec.soa.entidades.PropostaContrato;
import br.np2tec.soa.entidades.TaxaContrato;
import java.util.List;
import javax.jws.WebService;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author np2tec-07
 */
@WebService()
@Stateless()
public class TratarTaxaContratoDataService {
    @PersistenceContext(unitName = "TaxaContratoDataServicePU")
    EntityManager em;

    public void incluirTaxaContrato(TaxaContrato taxaContrato) {
        em.persist(taxaContrato);

    }

    public void alterarTaxaContrato(TaxaContrato taxaContrato) {
        em.merge(taxaContrato);
    }

    public void excluirTaxaContrato(TaxaContrato taxaContrato) {
        TaxaContrato tc = em.find(TaxaContrato.class, new Long(taxaContrato.getId()));
        em.remove(tc);
    }

    public List<TaxaContrato> listarTaxaContrato() {

        return em.createQuery("select tc from TaxaContrato tc").getResultList();
    }

    public List<TaxaContrato> consultarTaxaContratoPorIdPropostaContrato(Long idPropostaContrato)
    {
        Query query = em.createQuery("SELECT tc FROM TaxaContrato tc WHERE tc.propostaContrato.id = :idPropostaContrato");
        query.setParameter("idPropostaContrato", idPropostaContrato);
        List<TaxaContrato> listaTaxaContrato = null;

        try {
            listaTaxaContrato = query.getResultList();
        } catch (javax.persistence.NoResultException nre) {
        }

        return listaTaxaContrato;
    }
}
